package org.jeecg.modules.assets.service.impl;


import cn.hutool.core.collection.CollectionUtil;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.util.TypeUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;
import lombok.val;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.api.ISysBaseAPI;
import org.jeecg.common.system.vo.DictModel;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.modules.assets.dto.*;
import org.jeecg.modules.assets.entity.*;
import org.jeecg.modules.assets.mapper.AssetsPreliminaryResultsMapper;

import org.jeecg.modules.assets.service.*;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.transaction.annotation.Transactional;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * @Description: 初盘结果管理
 * @Author: jeecg-boot
 * @Date: 2023-12-12
 * @Version: V1.0
 */
@Service
@Slf4j
public class AssetsPreliminaryResultsServiceImpl extends ServiceImpl<AssetsPreliminaryResultsMapper, AssetsPreliminaryResults> implements IAssetsPreliminaryResultsService {


    @Autowired
    @Lazy
    private IAssetsItemService assetsItemService;
    @Autowired
    private IAssetsPreliminaryResultsItemService assetsPreliminaryResultsItemService;
    @Autowired
    private IAssetsDoubleQuotationResultService assetsDoubleQuotationResultService;
    @Autowired
    @Lazy
    private IAssetsRandomStockService assetsRandomStockService;
    @Autowired
    private ISysBaseAPI isysBaseAPI;
    @Autowired
    private IAssetsStartService assetsStartService;
    @Autowired
    private IDeptExtService iDeptExtService;


    @Autowired
    private WechatUtils wechatUtils;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void startAssets(StartAssetsDTO startAssetsDTO) throws ParseException {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmm");
        SimpleDateFormat simpledf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        AssetsStart assetsStart = new AssetsStart();
        assetsStart.setStartTime(startAssetsDTO.getStartTime());
        assetsStart.setEndTime(startAssetsDTO.getEndTime());
        assetsStart.setStartType("1");
        assetsStart.setCompany(startAssetsDTO.getCompany());
        assetsStart.setStatus("0");
        assetsStartService.save(assetsStart);
        String unionId = "ZCCP-" + System.currentTimeMillis();
        //获取所有资产明细
        LambdaQueryWrapper<AssetsItem> lambad = new QueryWrapper<AssetsItem>().lambda();
        if (StringUtils.isNotEmpty(assetsStart.getCompany())) {
            lambad.in(AssetsItem::getCompany, assetsStart.getCompany().split(","));
        }
        List<AssetsItem> list = assetsItemService.list(lambad);
        if (CollectionUtil.isNotEmpty(list)) {
            //根据部门进行分组
            Map<Integer, List<AssetsItem>> deptMap = list.stream().collect(Collectors.groupingBy(AssetsItem::getDept));
            //定义计数器
            int count = 1;
            for (Map.Entry<Integer, List<AssetsItem>> deptEntry : deptMap.entrySet()) {
                List<AssetsItem> ietms = deptEntry.getValue();
                String deptName = ietms.get(0).getSimpleDeptName();
                //组装主表信息
                AssetsPreliminaryResults assetsPreliminaryResults = new AssetsPreliminaryResults();
                if (deptEntry.getKey() != null) {
                    Date startDate = simpledf.parse(startAssetsDTO.getStartTime());
                    String billNo = "GZPD-" + sdf.format(startDate);
                    //使用字符串格式化方法，在数字小于四位时在前面补0
                    String formattedNumber = String.format("%03d", count);
                    assetsPreliminaryResults.setBillNo(billNo + "-" + formattedNumber);
                    assetsPreliminaryResults.setDeptId(deptEntry.getKey());
                    //根据部门iD获取部门名称
                    assetsPreliminaryResults.setDeptName(deptName);
                    assetsPreliminaryResults.setAssetsNum(deptEntry.getValue().size());
                    assetsPreliminaryResults.setStartTime(startAssetsDTO.getStartTime());
                    assetsPreliminaryResults.setEndTime(startAssetsDTO.getEndTime());
                    assetsPreliminaryResults.setStatus("0");
                    assetsPreliminaryResults.setUniqueId(unionId);
                    assetsPreliminaryResults.setStartId(assetsStart.getId());
                    count++;
                    this.save(assetsPreliminaryResults);
                }
                //遍历明细信息，生产待盘点列表
                for (AssetsItem ietm : ietms) {
                    AssetsPreliminaryResultsItem assetsPreliminaryResultsItem = new AssetsPreliminaryResultsItem();
                    assetsPreliminaryResultsItem.setApplyId(assetsPreliminaryResults.getId());
                    assetsPreliminaryResultsItem.setAssetCoding(ietm.getAssetCoding());
                    assetsPreliminaryResultsItem.setAssetName(ietm.getAssetName());
                    assetsPreliminaryResultsItem.setOwner(ietm.getOwner());
                    assetsPreliminaryResultsItem.setUserer(ietm.getUserer());
                    assetsPreliminaryResultsItem.setStatus(ietm.getStatus());
                    assetsPreliminaryResultsItem.setDeptId(ietm.getDept());
                    assetsPreliminaryResultsItem.setDeptName(ietm.getSimpleDeptName());
                    assetsPreliminaryResultsItem.setUseTime(ietm.getUseTime());
                    assetsPreliminaryResultsItem.setNotInventoryQuantity(1);
                    assetsPreliminaryResultsItem.setAssetsNum(1);
                    assetsPreliminaryResultsItem.setSpec(ietm.getSpec());
                    assetsPreliminaryResultsItem.setInventoryQuantity(0);
                    assetsPreliminaryResultsItem.setInventoryStatus("0");
                    assetsPreliminaryResultsItem.setUniqueId(unionId);
                    assetsPreliminaryResultsItem.setCategory(ietm.getCategory());
                    assetsPreliminaryResultsItem.setInventoryType(ietm.getInventoryType());
                    assetsPreliminaryResultsItem.setAssetsLocation(ietm.getAssetsLocation());
                    //初盘明细添加公司
                    assetsPreliminaryResultsItem.setCompany(ietm.getCompany());
                    assetsPreliminaryResultsItem.setCompanyName(ietm.getCompanyName());
                    if (Objects.equals(assetsPreliminaryResultsItem.getInventoryType(), 2)) {
                        assetsPreliminaryResultsItem.setInventoryStatus("1");
                        assetsPreliminaryResultsItem.setPreliminaryStatus(1);
                    }
                    assetsPreliminaryResultsItemService.save(assetsPreliminaryResultsItem);
                }

            }


        }


    }

    /**
     * 获取未发起盘点任务
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void startAssetsJob() {
        SimpleDateFormat sdfdate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        LambdaQueryWrapper<AssetsStart> startLambda = new QueryWrapper<AssetsStart>().lambda();
        startLambda.le(AssetsStart::getStartTime, sdfdate.format(new Date()));
        List<AssetsStart> list1 = assetsStartService.list(startLambda.eq(AssetsStart::getStatus, "0"));
        if (CollectionUtil.isEmpty(list1)) {
            return;
        }

        for (AssetsStart assetsStart : list1) {
            List<SenWxAssetsDTO> senWxAssetsDTOS = new ArrayList<>();
            LambdaQueryWrapper<AssetsPreliminaryResults> relationLambda = new QueryWrapper<AssetsPreliminaryResults>().lambda();
            relationLambda.eq(AssetsPreliminaryResults::getStartId, assetsStart.getId());
            List<AssetsPreliminaryResults> list = this.list(relationLambda);
            //开始发起盘点
            if (CollectionUtil.isNotEmpty(list)) {
                //提前修改所有状态为已开始
                assetsPreliminaryResultsItemService.updateAssetsList(list);
                for (AssetsPreliminaryResults assetsPreliminaryResults : list) {

                    //获取关联明细
                    List<AssetsPreliminaryResultsItem> assetsPreliminaryResultsItemList = assetsPreliminaryResultsItemService.list(new QueryWrapper<AssetsPreliminaryResultsItem>().lambda().eq(AssetsPreliminaryResultsItem::getApplyId, assetsPreliminaryResults.getId()));
                    //如果明细不为空。
                    if (CollectionUtil.isNotEmpty(assetsPreliminaryResultsItemList)) {
                        //组装发送列表
                        for (AssetsPreliminaryResultsItem assetsPreliminaryResultsItem : assetsPreliminaryResultsItemList) {
                            SenWxAssetsDTO senWxAssetsDTO = new SenWxAssetsDTO();
                            senWxAssetsDTO.setBillNo(assetsPreliminaryResults.getBillNo());
                            senWxAssetsDTO.setUserName(assetsPreliminaryResultsItem.getUserer());
                            senWxAssetsDTO.setOwnerName(assetsPreliminaryResultsItem.getOwner());
                            senWxAssetsDTO.setUnionId(assetsPreliminaryResultsItem.getUniqueId());
                            senWxAssetsDTOS.add(senWxAssetsDTO);
                        }
                    }

                    this.updateById(assetsPreliminaryResults);

                }
            }

            if (CollectionUtil.isNotEmpty(senWxAssetsDTOS)) {
                //组装发送列表
                Map<String, String> senWxAssetsDTOMap = new HashMap<>();
                senWxAssetsDTOS.stream().forEach(item -> {
                    senWxAssetsDTOMap.put(item.getOwnerName(), item.getBillNo());
                    senWxAssetsDTOMap.put(item.getUserName(), item.getBillNo());

                });
                for (String key : senWxAssetsDTOMap.keySet()) {
                    LoginUser userByRealName = isysBaseAPI.getUserByRealName(key);
                    JSONObject json = new JSONObject();
                    json.put("billNo", senWxAssetsDTOMap.get(key));
                    json.put("end_time", assetsStart.getEndTime());
                    wechatUtils.sendWechatMessage(userByRealName.getId(), senWxAssetsDTOMap.get(key), assetsStart.getEndTime());
                }


            }
            assetsStart.setStatus("1");
            assetsStartService.updateById(assetsStart);

        }
    }


    @Override
    public AssetsListDTO getUsetAssetsInfo(AssetsPreliminaryResults assetsPreliminaryResults, Page page, String queryType, String assetName,
                                           String inventoryStatus,
                                           Integer preliminaryStatus,
                                           String company,
                                           String asset
    ) {
        AssetsListDTO assetsListDTO = new AssetsListDTO();
        //获取当前登录用户
        LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        //根据用户id和盘点id获取盘点明细
        Page<AssetsPreliminaryResultsItem> resultPage = null;
        int haveNum = 0;
        Long badNum = 0L;
        Long assingNum = 0L;
        if (Objects.equals(queryType, "1")) {
            if (Objects.equals(company, "1200")) {
                resultPage = assetsPreliminaryResultsItemService.getAssetsItem(page, loginUser.getRealname(), assetsPreliminaryResults.getUniqueId(), inventoryStatus, preliminaryStatus, company, assetsPreliminaryResults.getId(), asset);
            } else {
                resultPage = assetsPreliminaryResultsItemService.getAssetsItem(page, loginUser.getRealname(), assetsPreliminaryResults.getUniqueId(), inventoryStatus, preliminaryStatus, company, null, asset);
            }

            LambdaQueryWrapper<AssetsPreliminaryResultsItem> lambda = new <AssetsPreliminaryResultsItem>QueryWrapper().lambda();
            lambda.eq(AssetsPreliminaryResultsItem::getUniqueId, assetsPreliminaryResults.getUniqueId());
            lambda.eq(AssetsPreliminaryResultsItem::getApplyId, assetsPreliminaryResults.getId());
            lambda.eq(AssetsPreliminaryResultsItem::getCompany, company);
            lambda.eq(AssetsPreliminaryResultsItem::getPreliminaryStatus, "2");
            lambda.and(i -> {
                i.eq(AssetsPreliminaryResultsItem::getUserer, loginUser.getRealname());
                i.or().eq(AssetsPreliminaryResultsItem::getOwner, loginUser.getRealname());

            });
            badNum = assetsPreliminaryResultsItemService.count(lambda);
            haveNum = assetsPreliminaryResultsItemService.getHaveNum(loginUser.getRealname(), assetsPreliminaryResults.getUniqueId(), company);
            lambda = new <AssetsPreliminaryResultsItem>QueryWrapper().lambda();
            lambda.eq(AssetsPreliminaryResultsItem::getUniqueId, assetsPreliminaryResults.getUniqueId());
            lambda.eq(AssetsPreliminaryResultsItem::getApplyId, assetsPreliminaryResults.getId());

            lambda.and(i -> {
                i.eq(AssetsPreliminaryResultsItem::getUserer, loginUser.getRealname());
                i.or().eq(AssetsPreliminaryResultsItem::getOwner, loginUser.getRealname());

            });
            assingNum = assetsPreliminaryResultsItemService.count(lambda);

        } else {
            LambdaQueryWrapper<AssetsPreliminaryResultsItem> eq = new QueryWrapper<AssetsPreliminaryResultsItem>().lambda().eq(AssetsPreliminaryResultsItem::getUniqueId, assetsPreliminaryResults.getUniqueId()).eq(AssetsPreliminaryResultsItem::getDeptId, loginUser.getDepartIds());
            if (StringUtils.isNotEmpty(assetName)) {
                eq.like(AssetsPreliminaryResultsItem::getOwner, assetName);
            }
            if (StringUtils.isNotEmpty(inventoryStatus)) {
                eq.eq(AssetsPreliminaryResultsItem::getInventoryStatus, inventoryStatus);
            }
            if (preliminaryStatus != null) {
                eq.eq(AssetsPreliminaryResultsItem::getPreliminaryStatus, preliminaryStatus);
            }
            resultPage = assetsPreliminaryResultsItemService.page(page, eq);
            LambdaQueryWrapper<AssetsPreliminaryResultsItem> lambda = new <AssetsPreliminaryResultsItem>QueryWrapper().lambda();
            lambda.eq(AssetsPreliminaryResultsItem::getUniqueId, assetsPreliminaryResults.getUniqueId());
            lambda.eq(AssetsPreliminaryResultsItem::getApplyId, assetsPreliminaryResults.getId());
            lambda.eq(AssetsPreliminaryResultsItem::getPreliminaryStatus, "2");
            badNum = assetsPreliminaryResultsItemService.count(lambda);
            haveNum = assetsPreliminaryResultsItemService.getHaveNumDept(assetsPreliminaryResults.getId());
            lambda = new <AssetsPreliminaryResultsItem>QueryWrapper().lambda();
            lambda.eq(AssetsPreliminaryResultsItem::getUniqueId, assetsPreliminaryResults.getUniqueId());
            lambda.eq(AssetsPreliminaryResultsItem::getApplyId, assetsPreliminaryResults.getId());
            assingNum = assetsPreliminaryResultsItemService.count(lambda);
        }
        assetsListDTO.setItemPages(resultPage);
        assetsListDTO.setAssetsNum(assingNum);
        assetsListDTO.setHaveNum(haveNum);
        assetsListDTO.setStatus(assetsPreliminaryResults.getStatus());
        assetsListDTO.setUserName(loginUser.getRealname());
        assetsListDTO.setEndTime(assetsPreliminaryResults.getEndTime());
        assetsListDTO.setBadNum(TypeUtils.castToInt(badNum));
        assetsListDTO.setDeptName(assetsPreliminaryResults.getDeptName());
        assetsListDTO.setNoNum(TypeUtils.castToInt(assetsListDTO.getAssetsNum()) - assetsListDTO.getHaveNum());
        QueryWrapper doubleQw = new QueryWrapper();
        doubleQw.eq("preliminary_bill_no", assetsPreliminaryResults.getBillNo());
        AssetsDoubleQuotationResult doubleQuotationResult = assetsDoubleQuotationResultService.getOne(doubleQw);
        if (doubleQuotationResult != null) {
            assetsListDTO.setDoubleBillNo(doubleQuotationResult.getBillNo());
        }
        return assetsListDTO;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Result optionAssetsItem(OptionPreliminaryAssetsItemDTO optionPreliminaryAssetsItem) {
        log.info("入参：" + JSONObject.toJSONString(optionPreliminaryAssetsItem));
        String msg = "盘点成功";
        //获取当前盘点人
        LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        optionPreliminaryAssetsItem.setUserName(user.getRealname());

        //更改初盘明细状态
        //根据扫码的code和当前登录人，判断是否可以修改
        //根据单据编号获取初盘单据
        if (StringUtils.isEmpty(optionPreliminaryAssetsItem.getBillNo())) {
            throw new RuntimeException("单据编号不能为空");
        }
        //根据单据号查询单据
        AssetsPreliminaryResults assetsPreliminaryResults = this.getOne(new QueryWrapper<AssetsPreliminaryResults>().eq("bill_no", optionPreliminaryAssetsItem.getBillNo()));

        QueryWrapper qw = new QueryWrapper();
        qw.eq("asset_coding", optionPreliminaryAssetsItem.getAssetCoding());
        qw.eq("apply_id", assetsPreliminaryResults.getId());
        AssetsPreliminaryResultsItem one = assetsPreliminaryResultsItemService.getOne(qw);
        log.info("获取初盘明细：" + JSONObject.toJSONString(one));
        if (one != null) {
            log.info("进行赋值操作：" + JSONObject.toJSONString(one));
            optionPreliminaryAssetsItem.setCompany(one.getCompany());
        }


        log.info("操作对象：" + JSONObject.toJSONString(optionPreliminaryAssetsItem));
        // optionPreliminaryAssetsItem.setApplyId(assetsPreliminaryResults.getId());
        AssetsPreliminaryResultsItem assetsPreliminaryResultsItem = assetsPreliminaryResultsItemService.getPrinallItemByCodeAndUser(optionPreliminaryAssetsItem);
        if (assetsPreliminaryResultsItem == null) {
            msg = "该资产不属于当前盘点人";
            optionPreliminaryAssetsItem.setUniqueId(assetsPreliminaryResults.getUniqueId());
            assetsPreliminaryResultsItem = assetsPreliminaryResultsItemService.getPrinallItemByCodeAndUser(optionPreliminaryAssetsItem);
            if (assetsPreliminaryResultsItem == null) {
                throw new RuntimeException("该资产既不属于该部门，又不属于该用户");
            }

        }
        //通过字典配置公司校验是否需要盘点资产图片
        List<DictModel> lstDic = isysBaseAPI.queryDictItemsByCode("company_photo");
        if (lstDic != null && lstDic.stream().count() > 0) {
            String companyCode = optionPreliminaryAssetsItem.getCompany();
            List<DictModel> streamDicModel = lstDic.stream().filter(x -> x.getValue().equals(companyCode)).collect(Collectors.toList());
            if (streamDicModel != null && streamDicModel.stream().count() > 0) {
                if (StringUtils.isEmpty(optionPreliminaryAssetsItem.getAssetImageUrl())) {
                    throw new RuntimeException("公司【" + companyCode + "】盘点资产需要上传资产图片");
                }
            }
        }
        assetsPreliminaryResultsItem.setAssetImageUrl(optionPreliminaryAssetsItem.getAssetImageUrl());
        if (StringUtils.isNotEmpty(optionPreliminaryAssetsItem.getErrorDesc())) {
            assetsPreliminaryResultsItem.setMsgDesc(msg);
        }
        assetsPreliminaryResultsItem.setInventoryStatus("1");
        //修改状态为正常
        assetsPreliminaryResultsItem.setPreliminaryStatus(1);
        assetsPreliminaryResultsItemService.updateById(assetsPreliminaryResultsItem);
        return Result.OK(msg);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void endPreliminaryAssets() {
        //先查询状态为1的，并且截止时间小于当前时间
        SimpleDateFormat sdfdate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        QueryWrapper qw = new QueryWrapper();
        String format = sdfdate.format(new Date());
        List<AssetsStart> startList = assetsStartService.list(new QueryWrapper<AssetsStart>().eq("status", 1).le("end_time", format));
        if (CollectionUtil.isEmpty(startList)) {
            log.info("暂无匹配的任务");
            return;
        }
        for (AssetsStart assetsStart : startList) {
            QueryWrapper qwPreliminar = new QueryWrapper();
            qwPreliminar.eq("start_id", assetsStart.getId());
            List<AssetsPreliminaryResults> list = this.list(qwPreliminar);
            if (CollectionUtil.isNotEmpty(list)) {
                for (AssetsPreliminaryResults assetsPreliminaryResults : list) {
                    //修改状态
                    assetsPreliminaryResults.setStatus("2");
                    //根据复盘单号，获取复盘结果
                    QueryWrapper qwItem = new QueryWrapper();
                    qwItem.eq("apply_id", assetsPreliminaryResults.getId());
                    List<AssetsPreliminaryResultsItem> assetsDoubleQuotationResultItems = assetsPreliminaryResultsItemService.list(qwItem);
                    //修改所有未盘状态为异常
                    UpdateWrapper update = new UpdateWrapper();
                    update.set("preliminary_status", 2);
                    update.eq("apply_id", assetsPreliminaryResults.getId());
                    update.eq("inventory_status", "0");
                    assetsPreliminaryResultsItemService.update(update);
                    if (CollectionUtil.isNotEmpty(assetsDoubleQuotationResultItems)) {
                        QueryWrapper qwCount = new QueryWrapper();
                        qwCount.eq("apply_id", assetsPreliminaryResults.getId());
                        qwCount.eq("preliminary_status", 2);
                        long badNum = assetsPreliminaryResultsItemService.count(qwCount);
                        if (badNum > 0) {
                            assetsPreliminaryResults.setPreliminaryBadNum(TypeUtils.castToInt(badNum));
                            assetsPreliminaryResults.setStatus("3");
                        } else {
                            assetsPreliminaryResults.setPreliminaryBadNum(0);
                            assetsPreliminaryResults.setStatus("2");
                        }
                        assetsPreliminaryResults.setDoubleQuotationNum(assetsDoubleQuotationResultItems.size());
                    }
                    this.updateById(assetsPreliminaryResults);

                    //初盘结束，给部门领导发送消息
                    //根据部门id获取部门领导
                    LambdaQueryWrapper<DeptExt> lambda = new QueryWrapper<DeptExt>().lambda();
                    lambda.eq(DeptExt::getDeptId, assetsPreliminaryResults.getDeptId());
                    DeptExt dept = iDeptExtService.getOne(lambda);
                    wechatUtils.sendWechatEndMessage(dept.getDeptUserId(), assetsPreliminaryResults);
                    wechatUtils.sendWechatEndMessage(dept.getAssetsUserId(), assetsPreliminaryResults);


                }

            }
            assetsStart.setStatus("3");
            assetsStartService.updateById(assetsStart);
        }

    }

    @Override
    public String queryStatusByBillNo(String billNo, String queryType) {
        switch (queryType) {
            //初盘
            case "1":
                AssetsPreliminaryResults assetsPreliminaryResults = this.getOne(new QueryWrapper<AssetsPreliminaryResults>().eq("bill_no", billNo));
                if (assetsPreliminaryResults == null) {
                    throw new RuntimeException("该单据不存在");
                }
                return assetsPreliminaryResults.getStatus();
            //复盘
            case "2":
                AssetsDoubleQuotationResult billNo1 = assetsDoubleQuotationResultService.getOne(new QueryWrapper<AssetsDoubleQuotationResult>().eq("bill_no", billNo));
                if (billNo1 == null) {
                    throw new RuntimeException("该单据不存在");
                }
                return billNo1.getStatus();
            case "3":
                throw new RuntimeException("暂未开启");

            default:
                throw new RuntimeException("无法匹配");

        }

    }
}
